package com.example.mapper;

import com.example.entity.Teacher;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


public interface TeacherMapper {

    @Insert("INSERT INTO teacher (username,password,name,sex,title,speciality_id,role,avatar) VALUES " +
            "(#{username},#{password},#{name},#{sex},#{title},#{specialityId},#{role},#{avatar})")
    void insert(Teacher teacher);

    @Select("SELECT * FROM teacher WHERE username=#{username}")
    Teacher selectByUsername(String username);

    @Select("SELECT t.*,s.`name` specialityName FROM teacher t LEFT JOIN speciality s ON t.speciality_id=s.id " +
            "WHERE t.`name` LIKE CONCAT('%',#{name},'%')")
    List<Teacher> selectByName(String name);

    @Select("SELECT t.*,s.`name` specialityName FROM teacher t LEFT JOIN speciality s ON t.speciality_id=s.id")
    List<Teacher> selectAll();

    @Update("UPDATE teacher SET username=#{username},password=#{password},name=#{name},sex=#{sex},title=#{title}," +
            "speciality_id=#{specialityId},role=#{role},avatar=#{avatar} WHERE id=#{id}")
    void updateById(Teacher teacher);

    @Select("select * from teacher where id=#{id}")
    Teacher selectById(Integer id);

    @Delete("delete from teacher where id=#{id}")
    void deleteById(Integer id);
}
